<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
        <meta name="format-detection" content="telephone=no">
        <title>通告详情</title>

        <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3.4/??flexible_css.js,flexible.js"></script>

        <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css"> 
        <link rel="stylesheet" href="./Public/awesome/font-awesome.min.css">
        <link rel="stylesheet" href="./Public/css/index.css">
        <script src="./Public/ga.js"></script>
        <script src="./Public/timeFormat.js"></script>
        <script src="./Public/frozenui/js/lib/zeptojs/zepto.min.js"></script>
        <script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script> 
        <script src="./Public/js/index.js"></script> 
        <script src="https://cdn1.lncld.net/static/js/av-min-1.5.0.js"></script>
        <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
        <script type="text/javascript">
            var href = window.location.href;
            var url = window.location.href.split('=');
            var annid = url[url.length-1];

            wx.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: 'wxf20953cc201449dd', // 必填，公众号的唯一标识
                timestamp: '{$Think.session.timestamp}', // 必填，生成签名的时间戳
                nonceStr: '{$Think.session.nonceStr}', // 必填，生成签名的随机串
                signature: '{$signature}',// 必填，签名，见附录1
                jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });
        
            wx.ready(function(){
                wx.onMenuShareTimeline({
                    title: '{$name}', // 分享标题
                    link: 'http://www.kmic168.com/?m=web&a=announcementPage&annid='+annid, // 分享链接,将当前登录用户转为puid,以便于发展下线
                    desc: '关注开麦，看更多主持通告',
                    imgUrl: 'http://www.kmic168.com/Public/img/logo.jpg', // 分享图标
                    success: function () { 
                        // 用户确认分享后执行的回调函数
                    },
                    cancel: function () { 
                        // 用户取消分享后执行的回调函数
                    },
                    trigger: function (res) {
    
                    },
                    fail: function (res) {
                    }
                });
                
                wx.onMenuShareAppMessage({
                    title: '{$name}', // 分享标题
                    desc: '实时更新，每次点开都有新通告噢', // 分享描述
                    link: 'http://www.kmic168.com/?m=web&a=announcementPage&annid='+annid, // 分享链接
                    imgUrl: 'http://www.kmic168.com/Public/img/logo.jpg', // 分享图标
                    type: 'link', // 分享类型,music、video或link，不填默认为link
                    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
                    success: function () { 
                        // 用户确认分享后执行的回调函数
                    },
                    cancel: function () { 
                        // 用户取消分享后执行的回调函数
                    }
                });
            });
        </script>

        <script>
            var APP_ID = '29f9bXMjtcmOkhtzRCWtVlgM-gzGzoHsz';
            var APP_KEY = 'FweIIrWPbdjifiD0GwQSEMna';
            AV.init({
              appId: APP_ID,
              appKey: APP_KEY
            });
        </script>
    </head>
        
    <body><input type="hidden" name="openid" value="{$Think.get.openid}" />

        <!-- header -->
        <header class="detail-header">
            <div class="back">
            </div>
            <div class="header-title">
                <p>详情</p>
            </div>     
        </header>

        <!-- 弹窗 -->
        <div class="f_windown1">
            <div class="bg"></div>
            <div class="ui-scroller">
                <div id="f_close1"><img src="./Public/Kmic/close.png" width="30"/></div>
                <div class="f_close_line"></div>
                <div class="windown-info">
                    <p>您的报价 (单位/元)</p>
                    <input name="price" type="text" placeholder="输入价钱 / 元" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')" >
                    <a class="sent" href="javascript:;">立即报名</a>
                </div>
            </div>
        </div> 

        <!-- section -->
        <section class="detail-section clearfix">
            <div class="col-xs-12 detail-item detail-item-title">
                <div class="col-xs-9 publish_user">
                    <img class="img-circle" src="./Public/img/2.jpg">
                    <span>开麦通告</span>
                </div>
                <div class="col-xs-3 modify-time"></div>     
            </div>

            <div class="col-xs-12 detail-item detail-item-activity">
                <p class="activity-title"></p>
                <div class="item-list">
                    <p>工作时间:<span class="activity-time"></span></p>
                </div>
                <div class="item-list">
                    <p>工作地点:<span class="activity-city"></span></p>
                </div>
                <div class="item-list">
                    <p>人员需求:<span class="sex"></span><span class="number"></span></p>
                </div>

            </div>

            <div class="col-xs-12 detail-item detail-item-content">
                <h4>详细描述</h4>
                <p class="original-desc content-text"></p>
            </div>

            <div class="col-xs-12 detail-item detail-item-content detail-item-contact">
                <h4>联系方式</h4>
                <p class="content-text contact"></p>
            </div>

            <!-- <div class="col-xs-12 detail-item-img"> 
                <img class="img-responsive" src="" alt="">
            </div> -->
        
        </section>

        <div class="detail-item detail-item-enroll">
            <div class="price">
                
            </div>
            <div class="signup">

            </div>
        </div>
    
    <script>
        $('.back').click(function() {
            var mine = window.location.href.indexOf('mine');
            if (mine != -1) {
                window.history.back();
            } else {
                window.location.href = '?m=web&c=index&openid={$Think.get.openid}&back'
            }
        });

        var openid = "{$Think.session.openid}";

        var aid = '{$aid}';
        $.ajax({
            type: 'GET',
            url: "?m=Web&a=announcementDetails",
            data: {'annid': aid},
            complete:function(result){
            //console.log('complete:function');
            },
            success: function(result){
                console.log(result);

                if (result.publish_user.headimgurl_user) {
                    $('.publish_user img').attr('src', result.publish_user.headimgurl_user);
                } else if (result.publish_user.headimgurl) {
                    $('.publish_user img').attr('src', result.publish_user.headimgurl);
                } else {
                    $('.publish_user img').attr('src', './Public/img/logo.jpg');
                }   

                if (result.publish_user.name_user) {
                    $('.publish_user span').html(result.publish_user.name_user);
                } else {
                    $('.publish_user span').html(result.publish_user.name);
                }
                
                

                var m_time = result.modify_time.substring(5,10);
                $('.modify-time').html(m_time);

                var a_time = result.activity_time==''?result.activity_time_input:result.activity_time.substring(5,10);
                if (a_time.substring(5,10)=='00-00') {
                    a_time = '';
                }
                $('.activity-time').html(a_time);


                var time = getDateDiff(result.modify_time);
                var img_url = './Public/Kmic/noPic.png';
                if (result.img_url != null) {

                    var dataobj = result.img_url;
                    if (dataobj != '[\"\"]') {
                        var pic = html_decode(dataobj[0]).replace(new RegExp(/(")/g),"");
                        var img_url = dataobj[0] =='' ?'./Public/Kmic/noPic.png':pic;
                        if (result.type == 0) {
                            img_url = dataobj[0] =='' ?result.wx_info.headimgurl:pic;
                        }else{
                            img_url = dataobj[0] =='' ?'./Public/Kmic/noPic.png':pic;
                        }
                        $('.detail-item-img').find('img').attr('src', img_url);   
                    } else {
                        $('.detail-item-img').remove();
                    } 
                                  
                }

                $('.activity-title').html(result.title);

                var city ='';
                if (result.city.length > 0) {
                    city = result.city;
                }else {
                    city = result.province;
                }
                $('.activity-city').html(city);

                var sex = '';
                if (result.sex==-1) {
                    sex = '不限';
                } else if (result.sex==0) {
                    sex = '{$Think.lang.L_SEX_M}主持';
                } else {
                    sex = '{$Think.lang.L_SEX_F}主持';
                }
                $('.sex').html(sex);

                $('.number').html(result.number + '名');

                $('.original-desc').html(result.original_desc);
                
                
                var price_h = '';
                var price = '';
                var priceText = '';
                if (result.price_h != null) {
                    if (result.price_h.length > 1) {
                        price_h = "-"+result.price_h;
                    }
                }
                if (result.price  == -1 || result.price == 0) {
                    priceText = '<p><span class="enroll-money">自报</span></p>';
                }else {
                    priceText += '<p><span class="enroll-sign">{$Think.lang.L_CURRENCY_SIGN}</span><span class="enroll-money">'+  result.price + '</span>/人'

                    

                    $('.f_windown1 p').html('确定报名吗？');
                    $('.f_windown1 input').remove();
                    $('.f_windown1 .sent').html('确定报名');
                    
                }                
                $('.price').append(priceText);


                var strVar = '';
                if (result.type == 1) {
                    strVar += '<button onclick="checkContact('+result.id+')">\n\
                                联系方式</button>';
                    $('.publish_user img').attr('src', './Public/img/logo.jpg');
                    $('.publish_user span').html('开麦通告');

                } else {
                    strVar += '<button onclick="open_f(event,\''+openid+'\',\''+result.title+'\',\''+result.price+'\',\''+time+'\',\''+result.id+'\','+result.type+',\''+result.wx_info.nickname+'\',\''+escape(img_url)+'\','+result.status+');">报名</button><button onclick="checkContact('+result.id+')">联系方式</button>';
                    
                
                }

                $('.signup').append(strVar);
            }
        });

        

        function html_decode(str) {   
            var s = "";   
            if (str.length == 0) return "";   
            s = str.replace(/&gt;/g, "&");   
            s = s.replace(/&lt;/g, "<");   
            s = s.replace(/&gt;/g, ">");   
            s = s.replace(/&nbsp;/g, " ");   
            s = s.replace(/&#39;/g, "\'");   
            s = s.replace(/&quot;/g, "\"");   
            s = s.replace(/<br>/g, "\n");   
            return s;   
        }

        function checkContact(id){

            ga('send', 'event', 'ann', 'checkContact', id);
            $.ajax({
                type: 'POST',
                url: "?m=web&a=sentContact",
                data: {'id':id,'action':'ann'},
                success: function(result){
                    if (result.error == 2 ) {
                        if(confirm(result.msg)) {
                            location.href= '?m=Center&c=profile&a=member&openid={$Think.session.openid}';
                        }
                    }else {
                        $('.contact').html(result.msg);
                    }
                    
                },
                dataType: 'json'
            });
        }

        
    </script>
    </body>
</html>
